<?php 

//Класс подключения к базе данных.
class connectDB
{
	private $connection;
	private $selected;
	private $query;
	private $result;
	public $adres;
	public $username;
	public $password;
	function __construct($adres,$username,$password)
	{
		$this->adres = $adres;
		$this->username = $username;
		$this->password = $password;
		$connection = mysql_connect("$adres","$username","$password");
		$this->connection = $connection;
		$selected = mysql_select_db('gb');
		$this->selected = $selected;
	}
	function connect()
	{
		$this->connect;
		$this->selected;
	}
}
//Класс ввода комментария в базу данных.
class inputCOM
{
	public $comment_id;
	public $comment;
	function __construct($comment_id,$comment)
	{
		$this->comment_id = $comment_id;
		$this->comment = $comment;
		//$this->date = $date;
		$this->connect = mysql_connect("localhost","root","123456");
		$this->selected = mysql_select_db('gb');
		$this->query = "INSERT INTO gb_comments(mess_id,comment)
		VALUES('$this->comment_id','$this->comment')";
		$this->result = mysql_query($this->query) || die(mysql_error());
	}

	function inCOM()
	{
		$this->connect;
		$this->selected;
		$this->result;


	}
}
//Класс изменения сообщения.
class change
{
	public $id;
	public $newmess;
	protected $selected;
	protected $query;
	protected $result;
	public function __construct($id,$newmess)
	{
		$this->id = $id;
		$this->newmess = $newmess;
		$selected = mysql_select_db('gb');
		$query = "UPDATE gb_messages SET mess = '$this->newmess' WHERE id = $this->id";
		$result = mysql_query($query) || die (mysql_error());
		$this->selected = $selected;
		$this->query = $query;
		$this->result = mysql_query($this->query);
	}
	function cha()
	{
		$this->selected;
		$this->result;
	}

}
//Класс вывода сообщений.
class outputmess
{
	private $query;
	private $result;
	public $data;

	function __construct()
	{
		$query = "SELECT gb_messages.id, gb_messages.name, gb_messages.mess
				  FROM gb_messages ORDER BY gb_messages.id DESC";
		$this->query = $query;
		$result = mysql_query($this->query);
		$this->result = $result;
	}

	function out()
	{
		$this->query;
		$this->result;
		while($row = mysql_fetch_assoc($this->result))
		{
			$id = $row['id'];
			$name = $row['name'];
			$mess = $row['mess'];
			include ('form.php');
		}
	}

}
//Класс ввода сообщения в базу данных.
class inputmess
{
	public $name;
	public $mess;
	public function __construct($name,$mess)
	{
		$this->name = $name;
		$this->mess = $mess;
		$this->query = "INSERT INTO gb_messages(name,mess)
		VALUES('$this->name','$this->mess')";
		$this->result = mysql_query($this->query);
	}
	function insert()
	{
		$this->selected;
		$this->result;
	}
}
//Класс перехода а главную страницу.
class redirect
{
	public $host;
	public $uri;
	public $extra;
	public $header;

	function __construct()
	{
		$host = $_SERVER['HTTP_HOST'];
		$uri = (rtrim(dirname($_SERVER['PHP_SELF']), '/\\'));
		$extra = 'index.php';
		$header = header("Location: http://$host$uri/$extra");
		$this->host = $host;
		$this->uri = $uri;
		$this->extra = $extra;
		$this->header = $header;
	}
	function red()
	{
		$this->host;
		$this->uri;
		$this->extra;
		$this->header;
	}
}

//Функция вывода комментариев на главную страницу.
function comment($id)
{
	$connect = mysql_connect("localhost","root","123456");
	$selected = mysql_select_db('gb');
	$query = "SELECT gb_comments.comment FROM gb_comments WHERE mess_id = $id";
	$result = mysql_query($query);
	while($menu_tree = mysql_fetch_assoc($result))
	{
		foreach ($menu_tree as $menu)
		{
			echo('<br>'."$menu".'<br>');
		}
		 

	}

}










?>